Data loading

library(ggplot2)
library(Seurat)
## Loading required package: SeuratObject
## Loading required package: sp
## 
## Attaching package: 'SeuratObject'
## The following objects are masked from 'package:base':
## 
##     intersect, t
library(RColorBrewer)
source("~/Documents/GitHub/SCTP_iMETA/Fig1/Eval_func.R")
## 
## Attaching package: 'MLmetrics'
## The following objects are masked from 'package:DescTools':
## 
##     AUC, Gini, MAE, MAPE, MSE, RMSE
## The following object is masked from 'package:base':
## 
##     Recall
## Type 'citation("pROC")' for a citation.
## 
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
## 
##     cov, smooth, var

TSNE representation of the single cell database used for prediction. Cells are colored by global type and subtype annotations respectively.

load("/Users/w435u/Documents/ST_SC/OUTPUT2_test/Seurat_SC_pred.RData")
col=brewer.pal(n = 11, name = "RdBu")

my_cols <- c("Epithelial cells"='#A4DFF2',
             "Mast cells"='#5C88DAFF',
             "Myeloids"='#00B5E2FF',
             "Stromal cells"='#7C878EFF',
             "T cells" ='#ff9a00',
             "B cells"='#CC0C00FF')

DimPlot(pred_sc_seurat, group.by = "Global_Cluster", reduction = "tsne", cols = my_cols)

out_name = "~/Documents/GitHub/SCTP_iMETA/Fig1/SC_DimPlot_Global_Cluster.pdf"
pdf(out_name)
DimPlot(pred_sc_seurat, group.by = "Global_Cluster", reduction = "tsne", cols = my_cols)
dev.off()
## quartz_off_screen 
##                 2

Prediction of cell phenotype (malignant vs. non-malignant) based on different spatial transcriptomic datasets by SCTP.

DimPlot(pred_sc_seurat, reduction = "tsne", group.by = c('sign_sc','sign_sc2','sign_sc3','sign_sc4' ), cols =  c(col[10], col[2]),  pt.size=0.00001)+ggtitle("")

ggsave("~/Documents/GitHub/SCTP_iMETA/Fig1/SC_DimPlot_pred_all.pdf")
## Saving 7 x 5 in image

Nonimmune cell malignancy prediction based on SCTP-CRC. TSNE presentation of cells, with cells colored by the predicted phenotype from SCTP-CRC

load("/Users/w435u/Documents/ST_SC/DATA_STSC_CAO/Seurat_nonimmune.RData")
load("/Users/w435u/Documents/ST_SC/OUTPUT_CAO_new/Meta_pred_sc_CAO_degree100.RData")
sc_nonimmune_pred <- AddMetaData(sc_nonimmune_seurat, metadata = metadata_sc100)
name_meta <- paste0("sign_", "C1", "_100")
pdf(paste0("~/Documents/GitHub/SCTP_iMETA/Fig1/TSNE_pred_SC", "C1", "_100.pdf"))
gg <- DimPlot(sc_nonimmune_pred, reduction = "tsne", group.by = name_meta, cols =  c("#053061", '#EB455F'), 
          order=c("negative","positive"), pt.size=0.0000001)+NoLegend() +ggtitle("")
print(gg)
dev.off()
## quartz_off_screen 
##                 2
print(gg)

True labels and SCTP-HCC predictions on independent HCC dataset.

label_colors <- c("tumor" = "#E075A0", "normal" ="#77aecb")

fig_all <- label_all <- list()
for (i in 1:4) {
  load(paste0("/Users/w435u/Documents/ST_SC/OUTPUT_HCC/spatial/ST-liver",i, "_seurat.RData"))
  fig_all[[i]] <- SpatialFeaturePlot(pred_st_dataset, "malignancy",  pt.size.factor = 2.5)+
 scale_fill_gradientn(colours = rev(brewer.pal(n = 11, name = "RdBu")))

  label_all[[i]] <- SpatialDimPlot(pred_st_dataset, "label",  cols = label_colors,, pt.size.factor = 2.5 )
  print(fig_all[[i]])
  print(label_all[[i]])
}
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.

Benchmarking prediction performance of SCTP and other three existing methods on independent HCC dataset, including accuracy, F1 score, AUC and Brier score.

eval_all =  matrix(NA, 4, 8)
eval_cf = eval_copykat = eval_meti = matrix(NA, 4, 8)

plot_methods <- c( "malignancy", "pred_meti", "pred_ck", "pred_cf")
for (i in (1:4)) {
  out_cf <- read.csv(paste0("~/Documents/GitHub/SCTP_iMETA/Fig1/out_HCC_liver",i,".csv"))
   pred_cf <- out_cf$predict
  copykat_prediction <- read.delim(paste0("~/Documents/GitHub/SCTP_iMETA/Fig1/ST-liver",i, "_copykat_prediction.txt"))
   rownames(copykat_prediction) <- copykat_prediction$cell.names
  #copykat_prediction$pred_cnv <- ifelse(substr(copykat_prediction$copykat.pred,1,2)=="c2", 1, 0)
  copykat_prediction$pred_cnv <- ifelse(substr(copykat_prediction$copykat.pred,1,2)=="an", 1, 0)
  #test <- merge(copykat_prediction, pred_st_dataset@meta.data, by=0, all=TRUE)
  
  METI_label <- read.csv(paste0("~/Documents/GitHub/SCTP_iMETA/Fig1/METI_label_liver",i, ".csv"), row.names=1)
  test <- merge(copykat_prediction, METI_label, by=0, all=TRUE)
  pred_meti <- ifelse(METI_label$label=="Tumor", 1, 0)
  SCTP_pred_liver1 <- read.csv(paste0("~/Documents/GitHub/SCTP_iMETA/Fig1/SCTP_pred_liver",i, ".csv"), row.names=1)
  test$pred_sctp <-  SCTP_pred_liver1
  test$pred_meti <- ifelse(METI_label$label=="Tumor", 1, 0)
  test$pred_cf <- pred_cf
  true_labels <- read.csv(paste0("~/Documents/GitHub/SCTP_iMETA/Fig1/ST_liver", i, "_true_labels.csv"), row.names=1)
  
  label <- ifelse(true_labels=="tumor", 1, 0 )
  
  eval_copykat[i, ] <- func_Eval(test$pred_cnv, label)
  eval_meti[i, ] <- func_Eval(test$pred_meti, label)
  eval_all[i, ] <- func_Eval(test$pred_sctp$x, resp_vec = label)
  eval_cf[i, ] <- func_Eval(test$pred_cf, label)
  #eval_all_old[i, ] <- func_Eval(pred_old, label)
}

my_blue <- "#095786"
my_red <- "#ae0000"
my_colors <- c("#E57470","#FBD37E", "#7A7DEE", "#A6DBFB")
df_plot <- data.frame(rbind(eval_all, eval_cf,eval_meti, eval_copykat))
colnames(df_plot) <- c("AUC", "AUCPR", "Brier", "F1","ACC", "LogLoss", "Sensitivity")
df_plot$method <- c(rep("SCTP",4), rep("CancerFinder", 4),rep("METI", 4), rep("copykat", 4))
df_plot$method <- factor(df_plot$method, levels = c("SCTP", "METI", "copykat", "CancerFinder"))
df_plot$data <- rep(c("HCC1", "HCC2","HCC3","HCC4"),4)

g_auc <- ggplot(df_plot, aes(data, AUC, group = method, fill=method))+
  geom_col( position = 'dodge',width = 0.8, alpha=1)+theme_bw()+
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.border = element_blank())+
  scale_y_continuous(breaks=c(seq(from=0,to=1,by=0.2)))+
  scale_fill_manual(values = my_colors)

g_f1 <- ggplot(df_plot, aes(data, F1, group = method, fill=method))+
  geom_col( position = 'dodge',width = 0.8, alpha=1)+theme_bw()+
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.border = element_blank())+
  scale_y_continuous(breaks=c(seq(from=0,to=1,by=0.2)))+
  scale_fill_manual(values = my_colors)


g_acc <- ggplot(df_plot, aes(data, ACC, group = method, fill=method))+
  geom_col( position = 'dodge',width = 0.8, alpha=1)+theme_bw()+
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.border = element_blank())+
  scale_y_continuous(breaks=c(seq(from=0,to=1,by=0.2)))+
  scale_fill_manual(values = my_colors)

g_sens <- ggplot(df_plot, aes(data, Sensitivity, group = method, fill=method))+
  geom_col( position = 'dodge',width = 0.8, alpha=1)+theme_bw()+
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.border = element_blank())+
  scale_y_continuous(breaks=c(seq(from=0,to=1,by=0.2)))+
  scale_fill_manual(values =my_colors)

g_Brier <- ggplot(df_plot, aes(data, Brier, group = method, fill=method))+
  geom_col( position = 'dodge',width = 0.8, alpha=1)+theme_bw()+
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.border = element_blank())+
  scale_y_continuous(breaks=c(seq(from=0,to=1,by=0.2)))+
  scale_fill_manual(values = my_colors)

library(ggpubr)

g <- ggarrange(
  g_acc,g_auc,g_f1, g_Brier , ncol=4, 
  common.legend = TRUE, legend = "bottom"
)

pdf(file="~/Documents/GitHub/SCTP_iMETA/Fig1/Eval_all_stat_new.pdf", width=12, height=4)
print(g)
dev.off()
## quartz_off_screen 
##                 2
print(g)

save(df_plot, file= "~/Documents/GitHub/SCTP_iMETA/Fig1/DF_plot_eval.RData")

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.